/*
 *******************************************************************************
 * All rights Reserved, Copyright (C) www.gm-sz.com 2013
 * FileName: leftbar.js
 * Modify record:
 * NO. |     Date       |    Version      |    Name         |      Content
 * 1   | 2013-11-11     |       1.0       |  GMSZ)GuoRuofei | original version
 *******************************************************************************
 */

/**
 * 左边栏
 */
var leftbar = leftbar || {};

leftbar.top = 0;
leftbar.step = 90;

leftbar.ws = null;

$(function() {
	if($(".lay-left-bar").find(".lay-left-item").size()==0){
		$(".lay-main").css("margin-left","0px");
		$("#leftBar").hide();
		$("#leftBarbtn1").hide();
		$("#leftBarbtn2").hide();
	} 

	
	$(window).resize(leftbar.showCurrent);
});


/**
 * Description: 将当前选中的菜单项移动至可视窗口内
 */
leftbar.showCurrent = function() {
	if ($('.lay-left-bar .com-active').length > 0) {
		leftbar.top = $('.lay-left').height() - $('.lay-left-bar .com-active').parent().position().top - leftbar.step;
		leftbar.setScroll();
	}
};

/**
 * Description: 菜单窗口上移
 */
leftbar.showUp = function() {
	leftbar.top += leftbar.step;
	leftbar.setScroll();
};

/**
 * Description: 菜单窗口下移
 */
leftbar.showDown = function() {
	leftbar.top -= leftbar.step;
	leftbar.setScroll();
};

/**
 * Description: 移动窗口，根据当前位置切换控制按钮的可用状态
 */
leftbar.setScroll = function() {
	var max = $('.lay-left-bar').height() - $('.lay-left').height();
	$('.lay-left-up').prop('disabled', false);
	$('.lay-left-down').prop('disabled', false);
	if (leftbar.top >= 0) {
		leftbar.top = 0;
		$('.lay-left-up').prop('disabled', true);
	}
	if (leftbar.top + max <= 0) {
		leftbar.top = -max;
		$('.lay-left-down').prop('disabled', true);
	}
	$('.lay-left-bar').css({
		top : leftbar.top
	});
};
